package com.huarui.company.util;

import java.util.Random;
public class JoinStringUtil {

	
	
	public static String getRandomNumber(Integer companyId){
		
		
		if(companyId==null){
			
			return "00000000";
		}
		
		String id = String.valueOf(companyId);
		
		if(id.length()>8){
			
			   int math = id.length()-8;
			   
			   id=id.substring(math,id.length());
			   
			
		}
		
		
		
		while(id.length()<8){
		
	         if(id.length()<8){
		         
	         id="0"+id;	  
		
		
	     }
      }
		
		return id;
		
	}
	
	public static String getDir(String dirNumber){
		
		String dir="";
		int i=0;
		  while(i<=6){
			  
			  
			  dir+=dirNumber.substring(i, i+2)+"/";
			  
			  
			  i=i+2;
		  }

	return dir;	  
		  
	}
	
	public  static  String getFilePath(Integer companyId,String envPath,String envPath2){
		
		    String  dirNumber = getRandomNumber(companyId);
		    String dir =getDir(dirNumber);
		    
		    StringBuffer bu = new StringBuffer();
		    
		    bu.append(envPath+"/");
		    bu.append(envPath2+"/");
		    bu.append(dir);
		    
		    return bu.toString();
		
	}
	//得到8位随机数
	public static String getCode(){
		
		 Random ra  = new  Random();
		 
		 StringBuffer sb = new StringBuffer();
		 
		 for(int i=0;i<8;i++){
			 int a = ra.nextInt(10);
			 sb.append(a);
		 }
		
		 return sb.toString();
	}
	                            
	public  static  String getHideCode(String data,int length){
		
		      if(data.length()<length){
		    	  
		    	  System.out.println("长度不合理");
		    	  
		    	  return "";
		    	  
		      }
		
		      
		       String  a =  data.substring(0,length);
		       
		       String b = data.substring(length);
		      
		       StringBuffer bu = new StringBuffer(); 
		       
		      for(int i=0;i<b.length();i++){
		    	  
		    	  
		    	    bu.append("*");
		    	
		      }
		       
		
		      String d = a.concat(b.replace(b,bu.toString()));
		
		return d;
	} 
	
	
	
	
	public static void main(String[] args) {
		
		String a=getRandomNumber(00000000);
		System.out.println(a);
		System.out.println(getDir(a));
		
		System.out.println(getFilePath(2,"/mnt/huarun/upload","templateCertifyPicture"));
		System.out.println(getFilePath(2,"http://www.ue3.com/upload","templateCertifyPicture"));
        System.out.println( getHideCode("66666666",6));
	}

}
